package com.trover.myapplication.core.http

import com.trover.myapplication.entity.LoginEntity
import com.trover.myapplication.entity.PlanEntity
import retrofit2.http.*

interface ApiService {
    companion object {
        const val BASE_URL = "http://49.4.2.82:8081/"

        /**
         * 网络层失败对应HTTP的状态码
         */
        const val ACCESS_TOKEN_EXPIRED = 201
        const val SUCCESS_NO_RESPONSE = 204
        const val BAD_REQUEST = 400
        const val UNAUTHORIZED = 401
        const val FORBIDDEN = 403
        const val NOT_FOUND = 404
        const val METHOD_NOT_ALLOWED = 405
        const val REQUEST_TIMEOUT = 408
        const val CONFLICT = 409
        const val PRECONDITION_FAILED = 412
        const val INTERNAL_SERVER_ERROR = 500
        const val BAD_GATEWAY = 502
        const val SERVICE_UNAVAILABLE = 503
        const val GATEWAY_TIMEOUT = 504
    }

    @GET("v1/api/patrol/plans")
    suspend fun getPlan(
        @Query("inspectorId") inspectorId: String,
        @Query("limit") limit: Int,
        @Query("offset") offset: Int,
        @Query("disabled") disabled: Boolean
    ): PlanEntity


    @FormUrlEncoded
    @POST("v1/api/signin")
    suspend fun login(
        @Field("username") username: String,
        @Field("password") password: String
    ): LoginEntity

}